<template>
  <div style="display: inline-block;margin-right: 5px;">
    <Modal v-model="modal1"
           title="编辑"
           ok-text="提交"
           :loading="loading"
           @on-ok="handleSubmit('formValidate')">
      <Form ref="formValidate"
            class="form"
            :model="formValidate"
            :label-width="100">
        <FormItem label="昵称"
                  class="form-item">
          <Input v-model="formValidate.NickName"
                 placeholder="请输入您的昵称" />
        </FormItem>
        <FormItem label="密码"
                  class="form-item">
          <Input v-model="formValidate.Pwd"
                 type="password"
                 placeholder="请输入您的密码" />
        </FormItem>
        <FormItem label="用户类型"
                  class="form-item"
                  prop="UserType">
          <Select v-model="formValidate.UserType">
            <Option v-for="item in UserType"
                    :value="item.number"
                    :key="item.number">{{ item.text }}</Option>
          </Select>
        </FormItem>
        <FormItem label="用户状态"
                  class="form-item"
                  prop="IsDisable">
          <Select v-model="formValidate.IsDisable">
            <Option v-for="item in IsDisable"
                    :value="item.number"
                    :key="item.number">{{ item.text }}</Option>
          </Select>
        </FormItem>
        <FormItem label="注册来源"
                  class="form-item">
          <Select v-model="formValidate.RegistSource">
            <Option v-for="item in RegistSource"
                    :value="item"
                    :key="item">{{ item }}</Option>
          </Select>
        </FormItem>
        <FormItem label="商品收藏数"
                  class="form-item">
          <Input v-model="formValidate.ProductCollectNum"
                 placeholder="请输入商品收藏数" />
        </FormItem>
        <FormItem label="关注店铺数"
                  class="form-item">
          <Input v-model="formValidate.AttentionShopNum"
                 placeholder="请输入关注店铺数" />
        </FormItem>
        <FormItem label="支付宝真实姓名"
                  class="form-item">
          <Input v-model="formValidate.AlipayName"
                 placeholder="请输入支付宝真实姓名" />
        </FormItem>
        <FormItem label="支付密码"
                  class="form-item">
          <Input v-model="formValidate.AlipayName"
                 type="password"
                 placeholder="请输入支付密码" />
        </FormItem>
        <FormItem label="身份证号码"
                  class="form-item">
          <Input v-model="formValidate.IDCardNo"
                 placeholder="请输入身份证号码" />
        </FormItem>
        <FormItem label="真实姓名"
                  class="form-item">
          <Input v-model="formValidate.RealName"
                 placeholder="请输入真实姓名" />
        </FormItem>
        <FormItem label="每天奖励额"
                  class="form-item">
          <Input v-model="formValidate.EveryDayReward"
                 placeholder="请输入每天奖励额" />
        </FormItem>
        <FormItem label="用户积分"
                  class="form-item">
          <Input v-model="formValidate.Userintegral"
                 placeholder="请输入用户积分" />
        </FormItem>
        <FormItem label="奖励额"
                  class="form-item">
          <Input v-model="formValidate.RewardQuota"
                 placeholder="请输入奖励额" />
        </FormItem>
      </Form>
    </Modal>
  </div>
</template>

<script>
import { editUserDetail, getUserDetail } from '@/api/user'

export default {
  name: 'edit',
  data () {
    return {
      modal1: false,
      loading: true,
      IsDisable: [
        {
          number: 0,
          text: '禁用'
        },
        {
          number: 1,
          text: '启用'
        }
      ],
      UserType: [
        {
          number: 0,
          text: '用户'
        },
        {
          number: 1,
          text: '商家'
        },
        {
          number: 2,
          text: '授权人'
        }
      ],
      RegistSource: ['system', 'android', 'ios'],
      formValidate: {},
      currentColId: ''
    }
  },
  mounted () {
    this.init()
  },
  methods: {
    init () {
      this.modal1 = false
      this.loading = true
      this.formValidate = {}
      this.editData = {}
      this.handleReset('formValidate')
    },
    getItem (id) {
      this.handleReset('formValidate')
      this.currentColId = id
      const getData = {
        'UserId': id,
        'SysUserId': localStorage.getItem('userId')
      }
      getUserDetail(getData).then(res => {
        if (res.data.success) {
          this.formValidate = res.data.data
        } else {
          this.$Message.info(res.data.msg)
        }
      }).then(() => {
        this.modal1 = true
      })
    },
    handleSubmit (name) {
      this.formValidate.SysUserId = localStorage.getItem('userId')
      this.formValidate.UserID = this.currentColId
      editUserDetail(this.formValidate).then(res => {
        if (res.data.success) {
          this.modal1 = false
          this.loading = true
          this.$Message.info('编辑成功!')
        } else {
          this.modal1 = true
          this.loading = false
          this.$Message.info('编辑失败!')
        }
      }).then(() => {
        this.$emit('getList')
      })
    },
    // 重置表单
    handleReset (name) {
      this.$refs[name].resetFields()
    }
  }
}
</script>

<style lang="less" scoped>
.form {
  overflow: hidden;
  .form-item {
    float: left;
    width: 50%;
  }
}
</style>
